<template>
  <div class="mainpg">
    <div class="main_spac1" style="padding-bottom: 5px">
      <div class="main_white">
        <div class="boxdq"></div>
        <div>
          <el-table
            ref="multipleTable"
            v-loading="listLoading"
            element-loading-text="加载中"
            :data="tableData"
            fit
            highlight-current-row
            :header-row-class-name="headerReturn"
            size="small"
          >
            <el-table-column
              label="模板名称"
              :show-overflow-tooltip="true"
              prop="tem_name"
            />
            <el-table-column label="创建时间" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                {{
                  !scope.row ||
                  parseTime(scope.row.created_at + "000", "{y}-{m}-{d}")
                }}
              </template>
            </el-table-column>
            <el-table-column label="修改时间" :show-overflow-tooltip="true"
              ><template slot-scope="scope">
                {{
                  !scope.row ||
                  parseTime(scope.row.updated_at + "000", "{y}-{m}-{d}")
                }}
              </template>
            </el-table-column>
            <el-table-column label="操作" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <div v-if="scope.row.show_more_tem_list">
                  <el-button
                    size="mini"
                    @click="handleMoreTem(scope.row)"
                    type="primary"
                    class="more_tem_btn"
                    >多模板管理</el-button
                  >
                </div>
                <div v-else>
                  <el-button
                    size="mini"
                    @click="handleEdit(scope.row)"
                    type="primary"
                    >编辑</el-button
                  >
                  <el-button
                    size="mini"
                    type="info"
                    @click="handleReset(scope.row)"
                    >重置</el-button
                  >
                </div>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// 请求数据
import { get_muban_list, reset_template } from "@/api/global/globalPrint";
import { apiUrl, objKeySort, Md5 } from "@/utils/public";
import { parseTime } from "@/utils/index";
export default {
  props: {
    tableData: {
      type: Array,
      default: [],
    },
  },
  data() {
    return {
      // 时间
      parseTime,
      listLoading: true,
      dialogTableVisible: false,
      // 多模板管理赛选
      more_tem_list: ["配送单模板"],
    };
  },
  created() {
    // this.getmubanlist();
  },

  methods: {
    // 加载模板列表
    getmubanlist() {
      let data = Object.assign(
        apiUrl().name
      );
      get_muban_list(data).then((res) => {
        if (res.errcode == 0) {
          res.list.map((e) => {
            if (this.more_tem_list.includes(e.tem_name)) {
              e.show_more_tem_list = true;
            } else {
              e.show_more_tem_list = false;
            }
          });
          this.tableData = res.list;
          this.listLoading = false;
        }
      });
    },
    // 表头默认
    headerReturn() {
      return "bgc";
    },
    handleEdit(row) {
      let id = row.id;
      let tem_id = row.tem_id;
      if (row.tem_name == "分拣小票模板") {
        let routeData = this.$router.resolve({
          name: "sortprint",
          query: {
            id: id,
            tem_id: tem_id,
          },
        });
        window.open(routeData.href, "_blank");
      } else {
        let routeData = this.$router.resolve({
          name: "orderprint",
          query: {
            id: id,
            tem_id: tem_id,
          },
        });
        window.open(routeData.href, "_blank");
      }
    },
    handleReset(row) {
      let id = row.id;
      let data = Object.assign(
        apiUrl().name,
        { id: id }
      );
      reset_template(data).then((res) => {
        if (res.errcode == 0) {
          this.getmubanlist();
          this.$message.success("重置成功");
        } else {
          this.$message.error("操作失败");
        }
      });
    },
    // 多模板管理跳转
    handleMoreTem(row) {
      this.$router.push("/global/system/printset/" + row.tem_id);
    },
  },
};
</script>

<style lang="scss" scoped>
.bgc {
  background-color: #cccccc;
}
/deep/ .el-table .el-table__header {
  color: #181818;
  border-bottom: 0;
}
/deep/ .el-table {
  border: 1px solid #ebeef5;
}
/deep/ .el-table th {
  background-color: #f7f7f7;
}
/deep/ .el-table--mini,
.el-table--small,
.el-table__expand-icon {
  font-size: 14px;
}
.main_spac1 {
  padding-top: 0;
}
/deep/ .more_tem_btn {
  span {
    display: block;
    width: 87px;
  }
}
</style>